#ifndef HASH_H
#define HASH_H
#include "gx_hashfcn.h"

typedef struct _hash_node
{
	struct _hash_node *next;
	struct _hash_node *prev;
	void *key;
	void *data;
}HASH_NODE;

typedef struct _hash
{
	HASHFCN *hashfcn;
	HASH_NODE **table;

	int nrows;
	unsigned count;
	int crow;
	unsigned keysize;
	HASH_NODE* cnode;
}HASH,SET;

HASH* 			hash_new(int nrows,unsigned keysize);
void  			hash_delete(HASH *h,void (*free_key)(void *),void(*free_data)(void*));
int   			hash_add(HASH *h,void *key,void *data);
void* 			hash_find(HASH *h,void *key);
int   			hash_remove(HASH *t ,void* key,void (*free_key)(void*),void(*free_data)(void*));
HASH_NODE* 		hash_findfirst(HASH *t);
HASH_NODE* 		hash_findnext(HASH *t);
int   			hash_set_keyops(HASH *h,unsigned(*hash_fcn)(HASHFCN*p,unsigned char*d,int n),int(*keycmp_fcn)(const void *s1,const void *s2,size_t n));

SET* 			set_new(int nrows,unsigned keysize);
void  			set_delete(SET *h,void (*free_key)(void *));
int   			set_add(SET *h,void *key);
int  			set_find(HASH *h,void *key);
int   			set_remove(SET *t ,void* key,void (*free_key)(void*));
#endif
